package com.ruoyi.activiti.controller;

import com.ruoyi.activiti.domain.DanWorkflowLeave;
import com.ruoyi.activiti.service.IDanWorkflowLeaveService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 请假Controller
 *
 * @author cjie
 * @date 2022-12-20
 */
@Api(tags = " 请假")
@RestController
@RequestMapping("/danWorkflowLeave")
public class DanWorkflowLeaveController extends BaseController {
    @Autowired
    private IDanWorkflowLeaveService danWorkflowLeaveService;

    /**
     * 查询请假列表
     */
    @ApiOperation(value="查询请假列表", notes="查询请假列表")
    @PreAuthorize(hasPermi = "activiti:danWorkflowLeave:list")
    @GetMapping("/list")
    public TableDataInfo list(DanWorkflowLeave danWorkflowLeave) {
        startPage();
        List<DanWorkflowLeave> list = danWorkflowLeaveService.selectDanWorkflowLeaveList(danWorkflowLeave);
        return getDataTable(list);
    }

    /**
     * 导出请假列表
     */
    @ApiOperation(value="导出请假列表", notes="导出请假列表")
    @PreAuthorize(hasPermi = "activiti:danWorkflowLeave:export")
    @Log(title = "请假", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanWorkflowLeave danWorkflowLeave) throws IOException {
        List<DanWorkflowLeave> list = danWorkflowLeaveService.selectDanWorkflowLeaveList(danWorkflowLeave);
        ExcelUtil<DanWorkflowLeave> util = new ExcelUtil<DanWorkflowLeave>(DanWorkflowLeave.class);
        util.exportExcel(response, list, "请假数据");
    }
    /**
     * 获取请假详细信息
     */
    @ApiOperation(value="获取请假详细信息", notes="获取请假详细信息")
    @PreAuthorize(hasPermi = "activiti:danWorkflowLeave:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(danWorkflowLeaveService.selectDanWorkflowLeaveById(id));
    }

    /**
     * 新增请假
     */
    @ApiOperation(value="新增请假", notes="新增请假")
    @PreAuthorize(hasPermi = "activiti:danWorkflowLeave:add")
    @Log(title = "请假", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DanWorkflowLeave danWorkflowLeave) {
        return toAjax(danWorkflowLeaveService.insertDanWorkflowLeave(danWorkflowLeave));
    }

    /**
     * 修改请假
     */
    @ApiOperation(value="修改请假", notes="修改请假")
    @PreAuthorize(hasPermi = "activiti:danWorkflowLeave:edit")
    @Log(title = "请假", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DanWorkflowLeave danWorkflowLeave) {
        return toAjax(danWorkflowLeaveService.updateDanWorkflowLeave(danWorkflowLeave));
    }

    /**
     * 删除请假
     */
    @ApiOperation(value="删除请假", notes="删除请假")
    @ApiImplicitParam(name = "ids", value = "请假ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "activiti:danWorkflowLeave:remove")
    @Log(title = "请假", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(danWorkflowLeaveService.deleteDanWorkflowLeaveByIds(ids));
    }
}
